﻿@using OBUCare.Core.Models
@using OBUCare.Web.Models
@using OBUCare.Web.Infrastructure
@using OBUCare.Core.Common;
@{
    ViewBag.Title = "List";

    var operatorInfo = UIUtility.GetCurrentUser();

    var menuName = PageData["moduleID"] == null ? UIUtility.getMenuName(Request.RawUrl) : PageData["moduleID"];
    ViewData["menuName"] = menuName;
    string AgentNo = UIUtility.getAgentByModule(operatorInfo, menuName.ToString());

}
<link href="../../Content/tableCss.css" rel="stylesheet" type="text/css" />
<table width="100%">
    <tr>
        <td style="text-align: center">
            <span style="font-weight: bold; font-size: 16px">维修单管理</span>
        </td>
    </tr>
    <tr>
        <td style="text-align: left">
            &nbsp;
        </td>
    </tr>
    <tr>
        <td style="text-align: left">
            @Html.Partial("_Search")
        </td>
    </tr>
    <tr>
        <td style="text-align: left">
            @(Html.Telerik().Grid<View_RepariOrders>()
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.ID))
        .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
        .ToolBar(toolBar => toolBar.Template
            (
            @<text>
                <table id="tblToolBar" width="100%">
                    <tr>
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/1"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/1" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnAgentToRepairCenter", "标签退维修组", "", GridButtonType.Text, new { @id = "btnAgentToRepairCenter", @value = 1, @style = "width:100px;font-size:14px;" }, null)
                                </td>}
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnAgentToRepairCenter", "标签退维修组", "", GridButtonType.Text, new { @id = "btnAgentToRepairCenter", @value = 1, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>}
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/3"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/3" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnRepairCenterToSupplier", "标签返厂商", "", GridButtonType.Text, new { @id = "btnRepairCenterToSupplier", @value = 3, @style = "width:100px;font-size:14px;" }, null)
                                </td>}
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnRepairCenterToSupplier", "标签返厂商", "", GridButtonType.Text, new { @id = "btnRepairCenterToSupplier", @value = 3, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td> }
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/5"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/5" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnConfirmedWithRepairByCustomer", "客户确认维修", "", GridButtonType.Text, new { @id = "btnConfirmedWithRepairByCustomer", @value = 5, @style = "width:100px;font-size:14px;" }, null)
                                </td>
                            }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnConfirmedWithRepairByCustomer", "客户确认维修", "", GridButtonType.Text, new { @id = "btnConfirmedWithRepairByCustomer", @value = 5, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>}
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/5"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/5" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnConfirmedWithoutRepairByCustomer", "客户确认不维修", "", GridButtonType.Text, new { @id = "btnConfirmedWithoutRepairByCustomer", @value = 5, @style = "width:100px;font-size:14px;" }, null)
                                </td> }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnConfirmedWithoutRepairByCustomer", "客户确认不维修", "", GridButtonType.Text, new { @id = "btnConfirmedWithoutRepairByCustomer", @value = 5, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td> }
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/5"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/5" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnConnectionWithoutByCustomer", "未联系上客户", "", GridButtonType.Text, new { @id = "btnConnectionWithoutByCustomer", @value = 5, @style = "width:100px;font-size:14px;" }, null)
                                </td>}
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnConnectionWithoutByCustomer", "未联系上客户", "", GridButtonType.Text, new { @id = "btnConnectionWithoutByCustomer", @value = 5, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td> }
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/6"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/6" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnInformeSupplierToRepair", "通知厂商维修", "", GridButtonType.Text, new { @id = "btnInformeSupplierToRepair", @value = 6, @style = "width:100px;font-size:14px;" }, null)
                                </td> }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnInformeSupplierToRepair", "通知厂商维修", "", GridButtonType.Text, new { @id = "btnInformeSupplierToRepair", @value = 6, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>}
                        }

                    </tr>
                    <tr>
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/8"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/8" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnSupplierToRepairCenter", "标签返回维修组", "", GridButtonType.Text, new { @id = "btnSupplierToRepairCenter", @value = 8, @style = "width:100px;font-size:14px;" }, null)
                                </td> }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnSupplierToRepairCenter", "标签返回维修组", "", GridButtonType.Text, new { @id = "btnSupplierToRepairCenter", @value = 8, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>}
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/9"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/9" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnRepairCenterToAgent", "标签返营业厅", "", GridButtonType.Text, new { @id = "btnRepairCenterToAgent", @value = 9, @style = "width:100px;font-size:14px;" }, null)
                                </td>}
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnRepairCenterToAgent", "标签返营业厅", "", GridButtonType.Text, new { @id = "btnRepairCenterToAgent", @value = 9, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>}
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/11"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/11" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnInformeCustomerToGetBack", "通知客户领签", "", GridButtonType.Text, new { @id = "btnInformeCustomerToGetBack", @value = 11, @style = "width:100px;font-size:14px;" }, null)
                                </td> }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnInformeCustomerToGetBack", "通知客户领签", "", GridButtonType.Text, new { @id = "btnInformeCustomerToGetBack", @value = 11, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td> }
                        }
                        @if (UIUtility.CheckAccessRight("/RepairOrders/List/11"))
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/11" || (AgentNo == "" && Request.Url.LocalPath == "/RepairOrders/List/"))
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnInformeWithoutCustomerToGetBack", "未联系上领签", "", GridButtonType.Text, new { @id = "btnInformeWithoutCustomerToGetBack", @value = 11, @style = "width:100px;font-size:14px;" }, null)
                                </td>
                            }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnInformeWithoutCustomerToGetBack", "未联系上领签", "", GridButtonType.Text, new { @id = "btnInformeWithoutCustomerToGetBack", @value = 11, @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>
                            }
                        }
                        @if (AgentNo == "")//如果为所有营业厅的权限 则显示
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/")
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnChangeCost", "费用调整", "", GridButtonType.Text, new { @id = "btnChangeCost", @style = "width:100px;font-size:14px;" }, null)
                                </td>
                            }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnChangeCost", "费用调整", "", GridButtonType.Text, new { @id = "btnChangeCost", @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>
                            }
                        }
                        @if (AgentNo == "")
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/")
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnCloseRepariOrder", "客户未领取", "", GridButtonType.Text, new { @id = "btnCloseRepariOrder", @style = "width:100px;font-size:14px;" }, null)
                                </td>
                            }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnCloseRepariOrder", "客户未领取", "", GridButtonType.Text, new { @id = "btnCloseRepariOrder", @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>
                            }
                        }
                        @if (AgentNo == "")//如果为所有营业厅的权限 则显示
                        {
                            if (Request.Url.LocalPath == "/RepairOrders/List/" || Request.Url.LocalPath == "/RepairOrders/List/3")
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnExport", "导出反馈数据", "", GridButtonType.Text, new { @id = "btnExport", @style = "width:100px;font-size:14px;" }, null)
                                </td>
                            }
                            else
                            {
                                <td style="text-align: center">
                                    @item.CustomCommandToolBarButton("btnExport", "导出反馈数据", "", GridButtonType.Text, new { @id = "btnExport", @style = "width:100px;font-size:14px;", @disabled = true }, null)
                                </td>
                            }
                        }
                        <td style="text-align: center">
                            @item.CustomCommandToolBarButton("btnExportList", "导出维修单信息", "", GridButtonType.Text, new { @id = "btnExportList", @style = "width:100px;font-size:14px;" }, null)
                        </td>
                    </tr>
                </table>
            </text>
                                                        )
                                                        )
                                                        .DataBinding(dataBinding => dataBinding
                                                        .Ajax()
                                                        .Select("ListSqlItems", "RepairOrders", new { sql = ViewBag.Sql })
                                                        .Insert("InsertEditing", "RepairOrders")
                                                        .Update("SaveEditing", "RepairOrders")
                                                        .Delete("Delete", "RepairOrders")
                                                        )
                                                        .Columns(columns =>
                                                        {
                                                            columns.Bound(o => o.ID)
                                                            .ClientTemplate("<input name='checkedRecords' type='checkbox'   value='<#= ID #>' title='选中当前行' /> <#= ++index #>")
                                                            .HeaderTemplate
                                                            (
                                                            @<text>
                                                                <input type="checkbox" title="全选" id="checkAllRecords" />
                                                            </text>).Width("5%");
                                                            columns.Bound(o => o.REPAIR_ORDER_NO).ClientTemplate("<a target='_blank' href='/RepairOrders/RepairOrderDetails/<#= ID #>'><#= REPAIR_ORDER_NO #></a>").Width("10%");
                                                            columns.Bound(o => o.OBU_NO).Width("7%");
                                                            columns.Bound(o => o.REPORTER).Width("15%");
                                                            columns.Bound(o => o.MOBILE_TEL_NO).Width("8%");
                                                            columns.Bound(o => o.CONFIRM_REPAIRED_Title).Width("6%");
                                                            //columns.Bound(o => o.IsNeedSPARE_OBU).Width("150px");
                                                            columns.Bound(o => o.SPARE_OBU_NO).Width("7%");
                                                            columns.Bound(o => o.SUPPLIER_ShortName).Width("5%");
                                                            columns.Bound(o => o.SPEC_NAME).Width("5%");
                                                            columns.Bound(o => o.REPORT_DATE).Format("{0:yyyy-MM-dd}").Width("5%");
                                                            columns.Bound(o => o.CREATED_DATE).Format("{0:yyyy-MM-dd}").Width("5%");
                                                            columns.Bound(o => o.AGENT_NAME).Width("5%");
                                                            columns.Bound(o => o.StatusTitle).Width("6%");
                                                            columns.Bound(o => o.STATUS).Hidden();
                                                            columns.Bound(o => o.OBU_NO)
                                                            .ClientTemplate("<input type='button' value='编辑' onclick='checkEdit(this)' name='<#=STATUS #>' />").Title("编辑").Width("5%");//TransferUrl
                                                            columns.Bound(o => o.ID)
                                                            .ClientTemplate("<input type='button' value='删除' name='deleteAll' id='<#= ID #>' dt='<#= CREATED_DATE #>' onclick='deleteData(id,dt)' />").Title("删除").Width("5%");
                                                        }).TableHtmlAttributes(new { @style = "width:240%" })
                                                                                                                                                                        .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                                                                                                                                                        .ClientEvents(events =>
                                                                                                                                                                        {
                                                                                                                                                                            events.OnEdit("onEdit");
                                                                                                                                                                            events.OnError("onError");
                                                                                                                                                                            events.OnDataBinding("onDataBinding");
                                                                                                                                                                        })
                                                                                                                                                                        .Pageable(paging =>
                                                                                                                                                                        {
                                                                                                                                                                            paging.Style(CommonStyleForUI.Grid_PageStyle)
                                                                                                                                                                            .Position(CommonStyleForUI.Grid_PagePosition)
                                                                                                                                                                            .PageTo(CommonStyleForUI.Grid_CurrentPage)
                                                                                                                                                                            .PageSize(CommonStyleForUI.Grid_PageSize, new int[] { 10, 20, 50, 100, 200, 500 });
                                                                                                                                                                        })
                                                                                                                                                                        .Scrollable(scroll => scroll.Height(CommonStyleForUI.Grid_Height)))
        </td>
    </tr>
</table>
<div>
    @using (Html.BeginForm("CreateTransfer", "Transfer", FormMethod.Post, new { @id = "form" }))
    {
        @Html.Hidden("strIDs", "", new { @id = "strIDs" });
        @Html.Hidden("TransferType", "", new { @id = "TransferType" });
    }
</div>

<!--删除弹出填写备注窗口-->
@{  Html.Telerik().Window()
        .Name("Window")
        .Title("确定删除？")
        .Content(@<text>
            <form id="delForm">
                <div>
                    <p>
                        <label for="txtRemark">
                            备注 <span style="color: red">*</span>
                        </label>
                        <input type="hidden" id="HidbillID" style="width: 0px;" />
                    </p>
                    <p>
                        <div>
                            <textarea id="txtRemark" class="{required:true,messages:{required:'请输入内容'}}" style="width: 370px; height: 100px;"></textarea>
                        </div>
                        <div>
                            <span id="valRemark" style="color: red">请输入备注</span>
                        </div>
                    </p>
                    <div style="float: right">
                        <button type="button" id="btnSumitDeleteForm" class="t-button t-state-default">
                            提交
                        </button>
                    </div>
                </div>
            </form>
        </text>)
        .Width(420)
        .Height(260)
        .Draggable(true)
        .Modal(true)
        .Visible(false)
        .Render();
}
<script type="text/javascript">
    ///////  2014.5.30新增 检查选中行是否有一口价维修
    function checkIsInCludOneRepair()
    {
        var result = false;
        $("#Grid tbody input:checkbox[name =checkedRecords][checked]").each(function () {
            var tds =$(this).parent().parent().find("td");
            if ($(tds[12]).html()=="一口价维修") {
                result = true;
            }
        });
        return result;
    }
    $().ready(function () {

        $('#tblToolBar tr').each(function(){
            if(($(this).find("td").length)>6)
                $('<tr>').insertAfter(this).append($('>:gt(5)',this));
        })

        $('#tblToolBar tr').each(function(){
            if(($(this).find("td").length)>6)
                $('<tr>').insertAfter(this).append($('>:gt(5)',this))
        })

        //为全选框注册事件
        $('#checkAllRecords').click(function () {
            $("#Grid tbody input:checkbox").attr("checked", this.checked);
        });

        $('#btnAgentToRepairCenter').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return Transfer(@TransferType.AgentToRepairCenter.ToInt());
            }

        });

        $('#btnRepairCenterToSupplier').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return Transfer(@TransferType.RepairCenterToSupplier.ToInt());
            }

        });

        $('#btnSupplierToRepairCenter').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return Transfer(@TransferType.SupplierToRepairCenter.ToInt());
            }
        });

        $('#btnRepairCenterToAgent').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return Transfer(@TransferType.RepairCenterToAgent.ToInt());
            }
        });

        $('#btnConfirmedWithRepairByCustomer').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return ConfirmWhetherToRepair(@ConfirmRepairedStatus.Repair.ToInt());
            }
        });

        $('#btnConfirmedWithoutRepairByCustomer').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return ConfirmWhetherToRepair(@ConfirmRepairedStatus.NotRepair.ToInt());
            }
        });

        $('#btnExport').click(function () {
            return  Export();
        });

        $('#btnExportList').click(function () {
            return ExportList();
        });

        $('#btnInformeSupplierToRepair').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return InformeSupplierToRepair();
            }
        });

        $('#btnInformeCustomerToGetBack').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return InformeCustomerToGetBack();
            }
        });

        $('#btnInformeWithoutCustomerToGetBack').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return InformeWithoutCustomerToGetBack();
            }
        });

        $('#btnCloseRepariOrder').click(function () {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return CloseRepariOrder();
            }
        });

        $('#btnConnectionWithoutByCustomer').click(function()
        {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                return ConnectionCustomers();
            }
        });

        $('#btnChangeCost').click(function()
        {
            if (checkIsInCludOneRepair()) {
                alert("选中的维修单中存在一口价维修，不允许操作！");
                return false;
            }else{
                changeCost();
            }

        });

        $("#btnSumitDeleteForm").click(function () {
            confirmDelete();
        });
    });
    function deleteData(value,dt)
    {
        var myDate= new Date(Date.parse(dt.replace(/-/g, "/")));
        var now = new Date();

        if (myDate.getFullYear()==now.getFullYear()&&myDate.getMonth()==now.getMonth()&&myDate.getDay()==now.getDay()) {
            if(confirm("确定删除？"))
            {
                $("#HidbillID").val(value);
                $("#valRemark").hide();
                $('#Window').data('tWindow').center().open();
                ////debugger;

            }
        }
        else {
            alert("只能删除今日的维修操作！");
        }
    }
    //点击删除弹出填写备注窗口中的保存按钮
    function confirmDelete() {
        var id = $("#HidbillID").val();
        var agentNo = $('#AgentNo').val();
        var txtRemark = $("#txtRemark").val();

        if (!txtRemark.StringIsNullOrEmpty()) {
            var jdata = {ID: id,Remark:txtRemark };
            $.post("/RepairOrders/DeleteData", jdata,
                        function (data) {
                            if (data.Success==true) {
                                var grid = $('#Grid').data('tGrid');
                                //                                alert(grid);
                                grid.rebind();
                                alert(data.ErrorMsg);
                                $('#Window').data('tWindow').center().close();
                            }
                            else {
                                alert(data.ErrorMsg);
                            }
                        });
        }
        else {
            $("#valRemark").show();
        }
    }

    function TransferUrl(no)
    {
        var tds =$(no).parent().parent().find("td");
        var obu_no =$(tds[2]).html();
        var id =$($(tds[0]).find("input")[0]).val();
        $.post("/RepairOrders/CheckTransferUrl/",{"obu_no":obu_no,"id":id},function(data){
            if(data.message=="true"){
                window.location ="/RepairOrders/EditOrder/"+id;
            }
            else{
                window.location ="/RepairOrders/NewOrderWithNoBaseInfo/"+id;
            }
        })

    }


    //获取被选中的ID
    function getCheckedOderIDs()
    {
        //获取被选中的ID
        var strBuff = new StringBuffer();
        $("#Grid tbody input:checkbox[name =checkedRecords][checked]").each(function () {
            strBuff.append(this.value);
        });
        strIDs = strBuff.arrayToString(",");
        return strIDs;
    }


    function getCheckedOderIDsAndSup()
    {
        //获取被选中的ID
        var strBuff = new StringBuffer();
        $("#Grid tbody input:checkbox[name =checkedRecords][checked]").each(function () {
            var tds =$(this).parent().parent().find("td");
            var supName = $(tds[7]).html();
            var agentName = $(tds[11]).html();
            strBuff.append(this.value+"-"+supName+"*"+agentName);
        });
        strIDs = strBuff.arrayToString(",");
        return strIDs;
    }

    function changeCost()
    {
        var id=getCheckedOderIDs();
        $('#btnChangeCost').attr("href", "/Cost?id="+id);
        $('#btnChangeCost').attr("target", "_blank");
    }

    //    //交接
    //    function Transfer(TransferType) {
    //        var status = "";    //记录前一条记录的状态
    //        var diff_i = 0;     //记录前后两条记录状态不相同的次数，如果>2(第一次不同是因为默认赋值为0)，表示所选记录状态不一致，不允许集体修改状态

    //        $("#TransferType").val(TransferType);

    //        var strBuff = new StringBuffer();

    //        $("#Grid tbody input:checkbox[name =checkedRecords][checked]").each(function () {
    //            //检查所选记录状态是否一致，只有一致时才允许修改
    //            if (status != this.title)
    //            {
    //                diff_i++;
    //            }
    //            strBuff.append(this.value);
    //        });
    //        if (diff_i > 1)
    //        {
    //            alert("请选择状态一致的维修单！");
    //            return false;
    //        }
    //        $("#strIDs").val(strBuff.arrayToString(","))

    //        //检查操作是否逆向
    //        $.post("/Transfer/checkIfValidOper", { "TransferType": TransferType, "itemIDs": strBuff.arrayToString(",") }, function (data) {
    //            //debugger;
    //            if ("" != data) {
    //                alert(data);
    //            }
    //            else {
    //                $('#form').submit();
    //            }
    //        })
    //        //alert($("#strIDs").val());
    //

    //        return false;
    //    }
    //交接 判断选中的状态是否一致
    function Transfer(TransferType) {
        //获取被选中的ID

        strIDs = getCheckedOderIDsAndSup();
        if (strIDs.length < 1)
            alert("请选中要确认的维修单");
        else {

            var jdata = {strIDs: strIDs };
            $.post("/RepairOrders/checkChangeValid", jdata,
                        function (data) {
                            if (data.success) {
                                $("#TransferType").val(TransferType);
                                $("#strIDs").val(strIDs);
                                $('#form').submit();
                            }
                            else {
                                alert("请选择状态一致的维修单！")
                            }
                        });
        }
        return false;
    }
    //确认是否维修
    function ConfirmWhetherToRepair(repair) {

        //获取被选中的ID
        strIDs = getCheckedOderIDs();
        if (strIDs.length < 1)
            alert("请选中要确认的维修单");
        else {

            var jdata = {
                strIDs: strIDs,
                repair: repair
            };
            $.post("/RepairOrders/ConfirmWhetherToRepair", jdata,
                        function (data) {
                            // Successful requests get here
                            // Update the page elements

                            if (data.success) {
                                var grid = $('#Grid').data('tGrid')
                                grid.rebind();
                                $('#checkAllRecords').attr("checked",false);
                                alert("确认成功");
                            }
                            else {
                                alert("确认失败:" + data.message)
                            }
                        });
        }
        return false;
    }

    function ConnectionCustomers()
    {
        //获取被选中的ID
        strIDs = getCheckedOderIDs();
        if (strIDs.length < 1)
            alert("请选中要确认的维修单");
        else {

            var jdata = {
                strIDs: strIDs
            };
            $.post("/RepairOrders/ConnectionWithoutCustomer", jdata,
                        function (data) {
                            // Successful requests get here
                            // Update the page elements

                            if (data.success) {
                                var grid = $('#Grid').data('tGrid')
                                grid.rebind();
                                $('#checkAllRecords').attr("checked",false);
                                alert("确认成功"+data.message);
                            }
                            else {
                                alert("确认失败:" + data.message)
                            }
                        });
        }
        return false;
    }

    //确认是否维修
    function Export() {
        //获取被选中的ID
        strIDs = getCheckedOderIDs();
        var result=false; //是否通过验证
        if (strIDs.length < 1)
            alert("请选中要导出的维修单");
        else {

            var jdata = {
                strIDs: strIDs
            };


            $.ajax({
                async:false, //使用同步的Ajax请求
                type: "POST",
                url: "/Import/CheckSameSuppliers",
                data: jdata,
                success: function (data) {
                    if (data.success) {
                        result = data.success;
                    }
                    else {
                        alert(data.message)
                    }
                }
            });


            $('#btnExport').attr("href", "/Import/Export?strIDs="+strIDs);
        }

        return result;
    }


    //确认是否维修
    function ExportList() {
        //获取被选中的ID
        strIDs = getCheckedOderIDs();
        var result = false; //是否通过验证
        if (strIDs.length < 1)
            alert("请选中要导出的维修单");
        else {
            result = true;
            $('#btnExportList').attr("href", "/Import/ExportOrderList?strIDs=" + strIDs);
        }

        return result;
    }


    //通知厂商维修
    function InformeSupplierToRepair() {
        //debugger;
        //获取被选中的ID
        strIDs = getCheckedOderIDs();
        var result=false; //是否通过验证
        if (strIDs.length < 1)
            alert("请选中要操作的维修单");
        else {

            var jdataForCheck = {
                strIDs: strIDs
            };

            $.ajax({
                async:false, //使用同步的Ajax请求
                type: "POST",
                url: "/Import/CheckSameSuppliers",
                data: jdataForCheck,
                success: function (data) {
                    if (data.success) {
                        result = data.success;
                    }
                    else {
                        alert(data.message)
                    }
                }
            });

            if(result)
            {
                var jdata = {
                    strIDs: strIDs
                };
                $.post("/RepairOrders/InformeSupplierToRepair", jdata,
                            function (data) {
                                // Successful requests get here
                                // Update the page elements

                                if (data.success) {
                                    var grid = $('#Grid').data('tGrid')
                                    grid.rebind();
                                    $('#checkAllRecords').attr("checked",false);
                                    alert("操作成功");
                                    result = data.success;
                                }
                                else {
                                    alert("操作失败:" + data.message)
                                }
                            });
            }
        }
        $('#btnInformeSupplierToRepair').attr("href", "/Import/Export?strIDs="+strIDs);
        return result;
    }

    //通知客户领取标签
    function InformeCustomerToGetBack() {
        //debugger;
        //获取被选中的ID
        strIDs = getCheckedOderIDs();

        if (strIDs.length < 1)
            alert("请选中要操作的维修单");
        else {

            var jdata = {
                strIDs: strIDs
            };
            $.post("/RepairOrders/InformeCustomerToGetBack", jdata,
                        function (data) {
                            // Successful requests get here
                            // Update the page elements

                            if (data.success) {
                                var grid = $('#Grid').data('tGrid')
                                grid.rebind();
                                $('#checkAllRecords').attr("checked",false);
                                alert("操作成功");
                            }
                            else {
                                alert("操作成功:" + data.message)
                            }
                        });
        }
        return false;
    }

    //未联系上客户领取标签
    function InformeWithoutCustomerToGetBack() {
        //debugger;
        //获取被选中的ID
        strIDs = getCheckedOderIDs();

        if (strIDs.length < 1)
            alert("请选中要操作的维修单");
        else {

            var jdata = {
                strIDs: strIDs
            };
            $.post("/RepairOrders/InformeWithoutCustomerToGetBack", jdata,
                        function (data) {
                            // Successful requests get here
                            // Update the page elements

                            if (data.success) {
                                var grid = $('#Grid').data('tGrid')
                                grid.rebind();
                                $('#checkAllRecords').attr("checked",false);
                                alert("操作成功！"+ data.message);
                            }
                            else {
                                alert("操作成功:" + data.message)
                            }
                        });
        }
        return false;
    }

    //关闭维修单
    function CloseRepariOrder() {
        //debugger;
        //获取被选中的ID
        strIDs = getCheckedOderIDs();

        if (strIDs.length < 1)
            alert("请选中要操作的维修单");
        else {

            var jdata = {
                strIDs: strIDs
            };
            $.post("/RepairOrders/CloseRepariOrder", jdata,
                        function (data) {
                            // Successful requests get here
                            // Update the page elements

                            if (data.success) {
                                var grid = $('#Grid').data('tGrid')
                                grid.rebind();
                                $('#checkAllRecords').attr("checked",false);
                                alert("操作成功");
                            }
                            else {
                                alert("操作成功:" + data.message)
                            }
                        });
        }
        return false;
    }

    function onEdit(e) {
        //编辑时将目前供应商值传给下拉框

        $(e.form).find('#SupplierDDL').data('tDropDownList').select(function (dataItem) {
            return dataItem.Text == e.dataItem['SUPPLIER_ShortName'];
        });
        //debugger
        var popup = $("#" + e.currentTarget.id + "PopUp");
        var popupDataWin = popup.data("tWindow");

        //popup.css({ "left": "700px", "top": "400px" });
        popupDataWin.center(); // Use if you'd rather center the dialog instead of explicitly postion it.

        if (e.mode == "insert")
            popupDataWin.title("添加");
        else
            popupDataWin.title("编辑");

        // Hide fields from the pop-up.
        //$(e.form).find("#ID").closest(".editor-field").prev().andSelf().hide();

    }
    function checkEdit(value)
    {

        var v=value.name;
        var agentNO=$('#agentNO').val();
        //如果权限为本营业厅 并且标签已退回维修组 则无权限编辑
        if(agentNO!="" && parseInt(v)>@RepairOrderStatus.ReadyForReturnToRepairGroup.ToInt() )
        {
            alert("该标签已进入维修流程，无操作权限，请联系维修组。");
        return false;
    }//如果维修单状态为客户已领取或客户未领取 维修结束状态 则不允许编辑
    else if(parseInt(v)==@RepairOrderStatus.ClosedWithoutCustomerPickedBack.ToInt()|| parseInt(v)==@RepairOrderStatus.ClosedWithCustomerPickedBack.ToInt() )
    {
        alert("该标签维修流程已结束，不允许编辑。");
        return false;
    }
    else
    {
        TransferUrl(value);
    }
    }
    function onError(e) {
        //debugger;
        e.preventDefault();
        /*if (e.XMLHttpRequest.status == "505")
            alert("系统字段不允许删除");
        else if (e.XMLHttpRequest.status == "506")
            alert("系统表不允许删除");
        else*/
        alert(e.XMLHttpRequest.getResponseHeader("message"));
    }

    var index = 0;

    function onDataBinding(e) {
        var grid = $('#Grid').data('tGrid')
        index = (grid.currentPage - 1) * grid.pageSize;
        e.data = {
            // the key ("category") specifies the variable name of the action method which will contain the specified value
            searchSql: $('#searchSql').val(),
            agentNO:$('#agentNO').val(),
            menuNames:$('#menuNames').val()
        };
    }



</script>
